package com.huika.dealontop.control.myinfo.holder;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.huika.dealontop.R;
import com.huika.dealontop.control.base.extend.BaseViewHolder;
import com.huika.dealontop.control.shops.activity.ProductDetailsActivity1;
import com.huika.dealontop.support.domain.OrderDetailBean;
import com.huika.dealontop.utils.DateTimeTool;
import com.huika.dealontop.utils.ImageLoaderHelper;
import com.huika.dealontop.utils.UIUtils;
import com.huika.huikalib.utils.MoneyShowTool;

/**
 * Author: Victor Wu
 * Email: victor-wu*foxmail.com
 * Time: 2015/11/19 11:32
 * Description: 订单详情顶部基本信息 区域
 */
public class OrderDetailBasicInfoHolder extends BaseViewHolder<OrderDetailBean> implements View.OnClickListener {
       
    private ImageView mIvIcon;
    private TextView mTvName;
    private TextView mTvCouponPrice;
    private TextView mTvCopies;
    private TextView mTvOrderId;
    private TextView mTvTotalPrice;
    private TextView mTvOrderState;
    private TextView mTvPayTime;
    private TextView mTvValidTime;
    private View mCouponTitle;

    public OrderDetailBasicInfoHolder(Context context) {
        super(context);
    }

    @Override
    protected View initView() {
        View view = View.inflate(UIUtils.getContext(), R.layout.holder_order_detail_base_info, null);
        mIvIcon = (ImageView) view.findViewById(R.id.iv_order_detail_icon);
        mTvName = (TextView) view.findViewById(R.id.tv_order_detail_title);
        mTvCouponPrice = (TextView) view.findViewById(R.id.tv_order_detail_coupon_price);
        mTvCopies = (TextView) view.findViewById(R.id.tv_order_detail_copies);
        mTvOrderId = (TextView) view.findViewById(R.id.tv_order_detail_orderId);
        mTvTotalPrice = (TextView) view.findViewById(R.id.tv_order_detail_totalPrice);
        mTvOrderState = (TextView) view.findViewById(R.id.tv_order_detail_state);
        mTvPayTime = (TextView) view.findViewById(R.id.tv_order_detail_payTime);
        mTvValidTime = (TextView) view.findViewById(R.id.tv_order_detail_validTime);
        mCouponTitle = view.findViewById(R.id.ll_coupon_title);
        view.findViewById(R.id.ll_order_detail_product_info).setOnClickListener(this);
        return view;
    }

    @Override
    protected void refreshView(OrderDetailBean data) {
        ImageLoaderHelper.displayRoundImage(data.getPicUrl(), mIvIcon, UIUtils.dip2px(3));
        mTvName.setText(data.getProductName());
        mTvCouponPrice.setText(MoneyShowTool.nolastDF(data.getCouponPrice()));
        mTvCopies.setText(data.getCopies() + UIUtils.getString(R.string.myorderlist_dish));
        mTvOrderId.setText(data.getOrderID());
        mTvTotalPrice.setText(MoneyShowTool.nolastDF(data.getTotalPrice()));
        mTvOrderState.setText(data.getActionHolder().stateStr);
        mTvPayTime.setText(DateTimeTool.dmyDate(data.getPlaceAnOrderTime()));
        mTvValidTime.setText(DateTimeTool.dmyDate(data.getValidTime()));
        mCouponTitle.setVisibility(data.getData() == null ? View.GONE : data.getData().size() > 0 ? View.VISIBLE : View.GONE);
    }

    @Override
    public void onClick(View view) {
        if(view.getId() == R.id.ll_order_detail_product_info){
            // 打开商品详情
            Intent intent = new Intent(mContext, ProductDetailsActivity1.class);
            intent.putExtra(ProductDetailsActivity1.PRODUCT_ID, mData.getProductID());
            intent.putExtra(ProductDetailsActivity1.PRODUCT_IMG, mData.getPicUrl());
            mContext.startActivity(intent);
        }
    }
}
